<?php
/**
 * Created by PhpStorm.
 * User: kongqi
 * Date: 2019/10/4
 * Time: 13:16
 */

namespace App\Plugin\HostServer\Models;

class PnHostSvCode extends HostServerBase
{
    public static function sendEmail($email)
    {
        $data = [
            'code' => mt_rand(100000, 999999),
            'type' => 'email',
            'account' => $email,
            'status' => 0,

        ];
        $r = self::create($data);
        return $r;
    }

    /**
     * 验证验证码
     * @param $code
     * @param $type
     * @param $account
     * @return bool
     */
    public static function checkCode($code, $type, $account)
    {
        $model = self::where('type', $type)->where('account', $account)->where('status', 0)->orderBy('id', 'desc')->first();
        if (empty($model)) {
            return false;
        }
        if ($model['code'] == $code) {
            return true;
        }
    }

    public static function codeUpdate($type, $account)
    {
        $r = self::where('type', $type)->where('account', $account)->update(['status' => 1]);
        return $r;
    }
    public static function codeUpdateCode($code,$type, $account)
    {
        $r = self::where('code',$code)->where('type', $type)->where('account', $account)->update(['status' => 1]);
        return $r;
    }
}